package com.ce.pms.system.occupation.service.impl;

import java.util.List;

import com.ce.common.util.BlankUtil;
import com.ce.pms.base.vo.SearchVO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.system.custservice.service.impl.AbstractCustomerEventServiceImpl;
import com.ce.pms.system.occupation.dao.IThingHandoverCongfigDao;
import com.ce.pms.system.occupation.model.ThingHandoverCongfigDO;
import com.ce.pms.system.occupation.service.IThingHandoverCongfigService;
import com.ce.pms.system.occupation.vo.ThingHandoverCongfigVO;
import com.sitechasia.webx.core.support.Page;
/**
 * 功能描述: 移交物品设置Service实现类
 * <p>版权所有：中企动力
 * <p>未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author  胡煦
 * Create on:2008-12-29
 * Edit author:
 * Edit on:
 * 修改原因：

 */

public class ThingHandoverCongfigServiceImpl extends AbstractCustomerEventServiceImpl<ThingHandoverCongfigVO,ThingHandoverCongfigDO>
		implements IThingHandoverCongfigService {

private IThingHandoverCongfigDao thingHandoverCongfigDao;
	/**
	 * 方法描述: 新增移交物品设置方法
	 * @author 胡煦
	 * Create on:2008-12-30
	 * @param thingHandoverCongfigVO
	 * @return ThingHandoverCongfigVO
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public ThingHandoverCongfigVO addThingHandoverCongfig(ThingHandoverCongfigVO thingHandoverCongfigVO)
	{
		checkNameExisited(thingHandoverCongfigVO.getThingHandoverCongfigName());
		if(BlankUtil.isBlank(thingHandoverCongfigVO) || BlankUtil.isBlank(thingHandoverCongfigVO.getThingHandoverCongfigName()))
		{
			return null;
		}
		ThingHandoverCongfigDO thingHandoverCongfigDO = assembleV2D(thingHandoverCongfigVO,null);
		thingHandoverCongfigDO.setSysInfo(createInfo(thingHandoverCongfigVO.getCreator()));
		thingHandoverCongfigDO = thingHandoverCongfigDao.saveObject(thingHandoverCongfigDO);
		thingHandoverCongfigVO.setKeyword(thingHandoverCongfigDO.getKeyword());
		return thingHandoverCongfigVO;
	}

	/**
	 * 方法描述: 验证移交物品设置项目名字是否存在
	 * @author 胡煦
	 * Create on:2008-12-29
	 * @param name
	 * @return void
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public void checkNameExisited(String name){
		if(isNameExisit(name)){
			throw new BusinessException(getNameExisitExceptionInoKey(),BusinessException.WARNING);
		}
	}
	/**
	 * 方法描述: 删除移交物品设置方法
	 * @author 胡煦
	 * Create on:2008-12-30
	 * @param thingHandoverCongfigId
	 * @return boolean
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public boolean deleteThingHandoverCongfigById(Long thingHandoverCongfigId)
	{
		if(thingHandoverCongfigId==null)
		{
			return false;
		}
		try
		{
			thingHandoverCongfigDao.deleteObjectById(thingHandoverCongfigId);
			return true;
		}
		catch(RuntimeException e)
		{	//如果发生异常，则认为是已经被引用，那么重新抛出异常
			throw new BusinessException("occupation:system_delete_inused_exception",BusinessException.WARNING);
		}
	}
	/**
	 * 方法描述: 修改移交物品设置方法
	 * @author 胡煦
	 * Create on:2008-12-30
	 * @param thingHandoverCongfigVO
	 * @return ThingHandoverCongfigVO
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public ThingHandoverCongfigVO editThingHandoverCongfig(ThingHandoverCongfigVO thingHandoverCongfigVO)
	{
		if(BlankUtil.isBlank(thingHandoverCongfigVO) || BlankUtil.isBlank(thingHandoverCongfigVO.getKeyword()))
		{
			return null;
		}
		ThingHandoverCongfigDO thingHandoverCongfigDO = thingHandoverCongfigDao.findById(thingHandoverCongfigVO.getKeyword());
		if(thingHandoverCongfigDO==null)
		{
			return null;
		}
		modifyInfo(thingHandoverCongfigDO.getSysInfo(), thingHandoverCongfigVO.getModifier());
		thingHandoverCongfigDO = super.assembleV2D(thingHandoverCongfigVO, thingHandoverCongfigDO);
		thingHandoverCongfigDao.updateObject(thingHandoverCongfigDO);
		return thingHandoverCongfigVO;
	}
	/**
	 * 方法描述: 判断移交物品设置名字是否存在
	 * @author 胡煦
	 * Create on:2008-12-29
	 * @param name
	 * @return void
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	protected boolean isNameExisit(String contractorInfoName){
		return thingHandoverCongfigDao.findUniqueByName(contractorInfoName)!=null;
	}
	/**
	 * 方法描述: 分页移交物品设置方法
	 * @author 胡煦
	 * Create on:2008-12-29
	 * @param searchVO
	 * @return Page
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public Page queryThingHandoverCongfigListByPage(SearchVO searchVO)
	{
		return queryVOListByPage(searchVO);
	}

	/**
	 * 方法描述: 查询移交物品设置List方法
	 * @author 胡煦
	 * Create on:2008-12-29
	 * @param
	 * @return List<OccupationChargeItemConfigVO>
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public List<ThingHandoverCongfigVO> queryAllThingHandoverCongfig()
	{
		List<ThingHandoverCongfigDO> thingHandoverCongfigDOList = thingHandoverCongfigDao.getThingHandoverCongfigList(null).getResult();
		return assembleDOList2VOList(thingHandoverCongfigDOList);
	}
	/**
	 * 方法描述: 根据ID查询移交物品设置VO方法
	 * @author 胡煦
	 * Create on:2008-12-29
	 * @param id
	 * @return ThingHandoverCongfigVO
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public ThingHandoverCongfigVO findThingHandoverCongfigVOById(Long id)
	{
		return super.findObjectVOById(id);
	}

	@Override
	protected ThingHandoverCongfigDO findObjectDOById(Long id)
	{
		return thingHandoverCongfigDao.findById(id);
	}


	@Override
	protected Page queryDOListByPage(SearchVO searchVO)
	{
		return thingHandoverCongfigDao.queryAllThingHandoverCongfigByPage(searchVO);
	}

	@Override
	protected String getNameExisitExceptionInoKey()
	{
		return "occupation:system_name_exist_exception";
	}


	/**
	 * @param thingHandoverCongfigDao the thingHandoverCongfigDao to set
	 */
	public void setThingHandoverCongfigDao(
			IThingHandoverCongfigDao thingHandoverCongfigDao) {
		this.thingHandoverCongfigDao = thingHandoverCongfigDao;
	}

}
